import { defineStore } from 'pinia'
import { reqHomeData } from "../api/home"


export const useHomeStore = defineStore("home", {
  state: () => {
    return {
      homeData: {},
      allData: {},
      rePic: [],
      categoryList: [],
      last: [],
      id:[]
    }
  },
  actions: {
    async getData() {
      const res = await reqHomeData()
      this.homeData = res.data.kingKongModule
      this.allData = res.data
      // this.categoryList = res.data.categoryHotSellModule
      let obj = {
        cateList1: res.data.categoryHotSellModule.categoryList.slice(0, 2).map((item: any) => {
          return {
            name: item.categoryName,
            pic: item.showPicUrl
          }
        }),
        cateList2: res.data.categoryHotSellModule.categoryList.map((item: any) => {
          return {
            name: item.categoryName,
            pic: item.showPicUrl
          }
        })
      }
      this.categoryList.push(obj)
      // this.rePic = res.data.bigPromotionModule.floorList
      // let obj1 = {
      //   rePic: res.data.bigPromotionModule.floorList.slice(0, 1).map((item: any) => {
      //     return {
      //       reImg: item.cells.map((item: any) => {
      //         return {
      //           reBgi: item.picUrl,
      //           reSwiper: item.itemList.map((item: any) => {
      //             return {
      //               reSwiper: item.picUrl
      //             }
      //           })
      //         }
      //       }),
      //       reList: item.cells.map((item: any) => {
      //         return {
      //           reList: item.itemList.map((item: any) => {
      //             return {
      //               reList: item.picUrl
      //             }
      //           })
      //         }
      //       })
      //     }
      //   })
      // }
      // this.rePic.push(obj1)
      // this.rePic.push(obj) 

      let obj2 = {
        last1: res.data.sceneLightShoppingGuideModule.slice(0, 1).map((item:any) => {
          return {
            picUrl: item.styleBanner.picUrl,
            title: item.styleBanner.title,
            desc:item.styleBanner.desc
          }
        }),
        last2: res.data.sceneLightShoppingGuideModule.slice(1, 1).map((item:any) => {
          return {
            picUrl: item.styleItem.picUrlList,
            title: item.styleItem.title,
            desc:item.styleItem.desc
          }
        })
      }
      this.last.push(obj2) 

      this.id = res.data.categoryHotSellModule.categoryList.map((item:any) => {
        return {
          id:item.extra.operationResource.categoryId
        }
      })
    
      // console.log("id",this.id)
      // console.log("homeData", this.homeData)
      // console.log("allData", this.homeData)
      
    }
  }
})